<?php

class Application_Model_VoucherMapper
{
	protected $_dbTable;

	public function setDbTable ($dbTable) {
		if (is_string($dbTable))
		$dbTable = new $dbTable ();
		if (!$dbTable instanceof Zend_Db_Table_Abstract)
		throw new Exception ('Invalid table data gateway provided');
		$this->_dbTable = $dbTable;
		return $this;
	}
	public function getDbTable () {
		if (null === $this->_dbTable) {
			$this->setDbTable ('Application_Model_DbTable_Voucher');
		}
		return $this->_dbTable;
	}

	public function getVoucher($code){//从数据库查询数据
		$where = $this->getDbTable()->getAdapter()->quoteInto('code = ?', $code);
		$result = $this->getDbTable()->fetchAll($where);
		return $result->toArray();
	}
	public function updateUser($id,$userid){
		$db = $this->getDbTable();
		$data = array (
			'user_id' => $userid,
			'status' => 1 ,
			'update_time'=>date("Y-m-d h:i:s")
			);
		$where = array ('id = ?' => $id);
		return $db->update($data, $where);
	}
	public function getVoucherList($userid){//从数据库查询数据		
		$select = $this->getDbTable()->select();
		$select->from($this->getDbTable(),'*');
		$select->where('user_id=?',$userid);
		$select->order('update_time DESC');
		$sql = $select->__toString();
		$result = $this->getDbTable()->getAdapter()->fetchAll($sql);
		return $result;
		
	}

}
?>
